package com.cellulam.log;

import com.cellulam.framework.core.auth.UserClient;
import com.cellulam.framework.core.log.LogClient;
import com.cellulam.properties.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LogAutoConfiguration {

    @Autowired(required = false)
    private UserClient userClient;

    @Bean
    @ConditionalOnMissingBean(LogClient.class)
    public LogClient logClient(SystemProperties systemProperties) {
        DurableLogClient durableLogClient = new DurableLogClient(systemProperties.getCellulamBasicHost(),
                systemProperties.getApplicationName());

        durableLogClient.setHttpTimeout(systemProperties.getHttpTimeout());
        durableLogClient.setUserClient(userClient);
        return durableLogClient;
    }
}
